import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import Defaults from '@/components/Defaults'
import User from '@/components/user/list'
import BookList from '@/components/book/list'
import EditBook from '@/components/book/edit'

Vue.use(Router)

var router = new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      redirect: '/default',
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'el-icon-location', // 图标样式class
      children: [
        { path: '/default', component: Defaults, name: '首页', menuShow: true }
      ]
    },
    {
      path: '/',
      component: Home,
      name: '用户管理',
      menuShow: true,
      leaf: true, // 只有一个节点
      iconCls: 'el-icon-menu', // 图标样式class
      children: [
        { path: '/user/list', component: User, name: '用户列表', menuShow: true }
      ]
    },
    {
      path: '/',
      component: Home,
      name: '图书管理',
      menuShow: true,
      iconCls: 'el-icon-document',
      children: [
        { path: '/book/list', component: BookList, name: '图书列表', menuShow: true },
        { path: '/book/category', component: Defaults, name: '图书分类', menuShow: true },
        { path: '/book/edit', component: EditBook, name: '编辑图书', menuShow: false }
      ]
    },
    {
      path: '/',
      component: Home,
      name: '设置',
      menuShow: true,
      iconCls: 'el-icon-setting',
      children: [
        { path: '/user/profile', component: Defaults, name: '个人信息', menuShow: true },
        { path: '/user/changepwd', component: Defaults, name: '修改密码', menuShow: true }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  // if (to.path === '/book/edit') {
  //   router.addRoutes([
  //     { path: '/book/edit', component: EditBook, name: '编辑图书', menuShow: false }
  //   ])
  // }
  console.log(to, from)
  next()
})

export default router
